import { sendRequest } from '@/http';

const baseUrl = '/admin/dap/student';

/**
 * 分页查询培训学员
 * @param params
 * @returns
 */
export const queryTraineeList = (params: {
  page: number;
  pageSize: number;
  name?: string; // 学员姓名
  householdTown?: string; // 户口所在镇/街道
}) => {
  return sendRequest({
    url: `${baseUrl}/queryStudents`,
    method: 'get',
    params: params as any,
  });
};

/**
 * 查询培训学员详情
 * @param studentId 学员ID
 * @returns
 */
export const queryTraineeDetails = (studentId: string) => {
  return sendRequest({
    url: `${baseUrl}/queryStudentInfo`,
    method: 'get',
    params: { studentId },
  });
};

/**
 * 创建培训学员
 * @param data
 * @returns
 */
export const createTrainee = (data: {
  name?: string;
  gender?: number;
  birthdate?: string;
  nationCode?: string;
  provinceCode?: string;
  cityCode?: string;
  districtCode?: string;
  maritalStatus?: number;
  politicalStatus?: string;
  educationLevel?: string;
  phoneNumber?: string;
  homeAddress?: string;
  postalCode?: string;
  idcardNo?: string;
  householdTown?: string;
  unemploymentCertificateNumber?: string;
  disabilityLevel?: string;
  disabilityDegree?: string;
  professionalTraining?: string;
  avatarResId?: string;
  idCardFrontResId?: string;
  idCardBackendResId?: string;
  disabilityFrontResId?: string;
  disabilityBackendResId?: string;
  contact?: {
    name?: string;
    relation?: string;
    incomeChannel?: string;
    unitName?: string;
    unitTitle?: string;
  }[];
}) => {
  return sendRequest({
    url: `${baseUrl}/createStudent`,
    method: 'post',
    data: data as any,
  });
};

/**
 * 更新培训学员
 * @param data
 * @returns
 */
export const updateStudent = (data: {
  id?: string;
  name?: string;
  gender?: number;
  birthdate?: string;
  nationCode?: string;
  provinceCode?: string;
  cityCode?: string;
  districtCode?: string;
  maritalStatus?: number;
  politicalStatus?: string;
  educationLevel?: string;
  phoneNumber?: string;
  homeAddress?: string;
  postalCode?: string;
  idcardNo?: string;
  householdTown?: string;
  unemploymentCertificateNumber?: string;
  disabilityLevel?: string;
  disabilityDegree?: string;
  professionalTraining?: string;
  avatarResId?: string;
  idCardFrontResId?: string;
  idCardBackendResId?: string;
  disabilityFrontResId?: string;
  disabilityBackendResId?: string;
  contact?: {
    name?: string;
    relation?: string;
    incomeChannel?: string;
    unitName?: string;
    unitTitle?: string;
  }[];
}) => {
  return sendRequest({
    url: `${baseUrl}/updateStudent`,
    method: 'post',
    data: data as any,
  });
};

/**
 * 删除培训学员
 * @param studentId 学员ID
 * @returns
 */
export const deleteStudent = (studentId: string) => {
  return sendRequest({
    url: `${baseUrl}/deleteStudent`,
    method: 'post',
    data: { studentId },
  });
};

/**
 * 生成资源上传TOKEN
 * @param data
 * @returns
 */
export const genResourceUploadToken = (data: { localFileName: string }) => {
  return sendRequest({
    url: `${baseUrl}/genResourceUploadToken`,
    method: 'post',
    data: data as any,
  });
};

/**
 * 更新学员头像
 * @param studentId 学员ID
 * @param resId 资源ID
 * @returns
 */
export const updateStudentAvatar = (
  studentId: string, 
  resId: number
) => {
  return sendRequest({
    url: `${baseUrl}/updateStudentAvatar`,
    method: 'post',
    data: { studentId, resId },
  });
};